package com.ms.education.course.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
import com.ms.education.JwtUtils;
import com.ms.education.R;
import com.ms.education.course.service.CourseCollectService;
import com.ms.education.exceptionHandler.EduException;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 课程收藏 前端控制器
 * </p>
 *
 * @author ms
 * @since 2023-02-16
 */
@RestController
@RequestMapping("/course/course-collect")
public class CourseCollectController {

    @Autowired
    private CourseCollectService courseCollectService;

    @GetMapping("isUserHasCourse/{courseId}")
    public R isUserHasCourse(@PathVariable("courseId") Integer courseId) {
        boolean has = courseCollectService.isUserHasCourse(Convert.toInt(StpUtil.getLoginId()), courseId);
        return R.ok().data("has", has);
    }

    @ApiOperation("取消收藏")
    @DeleteMapping("cancelCollect/{courseId}")
    public R cancelCollect(@PathVariable("courseId") Integer courseId) {
        courseCollectService.cancelCollect(courseId, Convert.toInt(StpUtil.getLoginId()));
        return R.ok();
    }

    @PutMapping("collectCourse/{courseId}")
    public R collectCourse(@PathVariable("courseId") Integer courseId) {
        courseCollectService.collectCourse(courseId, Convert.toInt(StpUtil.getLoginId()));
        return R.ok();

    }

}
